package com.example.hello.Scheduler;

import com.example.hello.service.OrderService;
import com.example.hello.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ShopScheduler {
    @Autowired
    private ProductService productService;

    @Autowired
    private OrderService orderService;

//    @Scheduled(cron = "0 0 23 * * *") // 每天零点触发
    @Scheduled(fixedRate = 2000) // 每天零点触发
    public void checkStockAndDeactivateProducts() {
        productService.checkStockAndDeactivateProducts();
    }

    @Scheduled(cron = "0 0 0 * * 1") // 每周一零点触发
    public void cleanExpiredOrders() {
        orderService.cleanExpiredOrders();
    }
}
